import {appendUrlParams} from "./appendUrlParams";

/**
 * 拼接 URL 参数
 * @param obj 要处理的参数对象
 * @param url 链接地址
 * @returns 处理后的 URL
 */
export function handleUrlQuery(url: string = "/", obj: { [key: string]: unknown } | null | undefined = {}): string {
  if (!obj || typeof obj !== "object") {
    throw new Error("错误参数: handleUrlQuery");
  }
  for (const objKey in obj) {
    url = appendUrlParams(url, objKey, <string>obj[objKey]);
  }
  return url;
}
export default handleUrlQuery;
